package com.gary.kafka;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.listener.MessageListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Slf4j
@Component
public class KafkaConsumerListener implements MessageListener<String, String> {


    @Override
    @KafkaListener(topics = {"topic1"})
    public void onMessage(ConsumerRecord<String, String> data) {
        try{
            log.info("接收kafka中的告警消息 data ={} " , data.value());
            if (!StringUtils.isEmpty(data.value())) {
                log.info("接收kafka中的告警消息 data ={} " , data.value());
            }
        }catch (Exception e){
            log.error("kafka消息转换异常 data = {} "+e.getMessage(), data.value(),e);
        }
    }




}